package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Video;
import com.atguigu.guli.service.edu.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-10-26
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/edu/video")
public class AdminVideoController {
    @Autowired
    VideoService videoService;

    @PostMapping("/save")
    public R save(@RequestBody Video video){
        boolean save = videoService.save(video);
        if(save){
            return R.ok().message("保存成功");
        }else {
            return R.error().message("保存失败");
        }
    }

    @GetMapping("/getById/{videoId}")
    public R getById(@PathVariable String videoId){
        Video video = videoService.getById(videoId);
        if (video != null) {
            return R.ok().data("item",video);
        }else{
            return R.error().message("数据不存在");
        }
    }

    @PutMapping("/update")
    public R update(@RequestBody Video video){
        boolean result = videoService.updateById(video);
        if(result){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }

    @DeleteMapping("/delete/{videoId}")
    public R delete(@PathVariable String videoId){
        boolean result = videoService.removeById(videoId);
        if(result){
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }
}

